package com.mxgraph.examples.swing;

//import SNMPManager;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JSplitPane;
import java.awt.Button;
import java.awt.TextArea;
import javax.swing.JLabel;
//import com.jgoodies.forms.factories.DefaultComponentFactory;
import java.awt.Checkbox;
import javax.swing.JMenuBar;
import java.awt.Canvas;
import java.awt.Panel;
import java.awt.FlowLayout;
import javax.swing.SwingConstants;
import java.awt.Label;
import java.awt.TextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.CardLayout;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;

import java.io.IOException;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;

public class deviceProperties extends JPanel 
{
	private JTextField typeTextField;
	private JTextField nameTextField;
	private JTextField locationTextField;
	private JTextField contactpersonTextField;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;
	private JTextField textField_10;
	private JTextField textField_11;
	private JTextField textField_12;
	private JTextField textField_13;
	private JTable table;
	Snmp snmp = null;
	String address = null;
	
	/**
	 * Create the panel.
	 */
	public deviceProperties(String add)
	{
	address = add;
	}
	public static void main(String[] args) throws IOException {
		/**
		* Port 161 is used for Read and Other operations
		* Port 162 is used for the trap generation
		*/
		deviceProperties client1 = new deviceProperties();
		client1.setVisible(true);
		
		deviceProperties client = new deviceProperties("udp:10.100.2.1/161");
		System.out.println("1");
		client.start();
		System.out.println("2");
		/**
		* OID - .1.3.6.1.2.1.1.1.0 => SysDec
		* OID - .1.3.6.1.2.1.1.5.0 => SysName
		* => MIB explorer will be usefull here, as discussed in previous article
		*/
		System.out.println("3");
		String sysDescr = client.getAsString(new OID("1.3.6.1.2.1.1.6"));
		String sysName = client.getAsString(new OID("1.3.6.1.2.1.1.5.0"));
		String sysLoca = client.getAsString(new OID("1.3.6.1.2.1.1.6.0"));
		String syscont = client.getAsString(new OID("1.3.6.1.2.1.1.4.0"));
		System.out.println("4");
		System.out.println(sysDescr);
		System.out.println(sysName);
		System.out.println(sysLoca);
		System.out.println(syscont);
		
		}
private void start() throws IOException
		{
		
		TransportMapping transport = new DefaultUdpTransportMapping();
		snmp = new Snmp(transport);
		// Do not forget this line!
		transport.listen();
		}
public String getAsString(OID oid) throws IOException
	{
	ResponseEvent event = get(new OID[] { oid });
	return event.getResponse().get(0).getVariable().toString();
	}
public ResponseEvent get(OID oids[]) throws IOException
{
PDU pdu = new PDU();
for (OID oid : oids)
{
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if(event != null) 
{
return event;
}
throw new RuntimeException("GET timed out");
}
private Target getTarget()
{
Address targetAddress = GenericAddress.parse(address);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("daeread"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
return target;
}
	public deviceProperties() 
	{
		setLayout(new CardLayout(0, 0));
		 
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		add(tabbedPane, "name_712889977339863");
		//tabbedPane.setVisible(true);
		JLayeredPane generalLayeredPane = new JLayeredPane();
		tabbedPane.addTab("General", null, generalLayeredPane, null);
		
		JLabel lblNewLabel = new JLabel("Type");
		lblNewLabel.setBounds(53, 52, 72, 14);
		generalLayeredPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Name");
		lblNewLabel_1.setBounds(53, 77, 72, 14);
		generalLayeredPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Location");
		lblNewLabel_2.setBounds(53, 102, 72, 14);
		generalLayeredPane.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("Contact Person Name");
		lblNewLabel_3.setBounds(53, 127, 105, 14);
		generalLayeredPane.add(lblNewLabel_3);
		
		JLabel lblNewLabel_4 = new JLabel("Information");
		lblNewLabel_4.setBounds(53, 11, 61, 14);
		generalLayeredPane.add(lblNewLabel_4);
		
		typeTextField = new JTextField();
		typeTextField.setEditable(false);
		typeTextField.setBounds(162, 49, 105, 20);
		generalLayeredPane.add(typeTextField);
		typeTextField.setColumns(10);
		
		nameTextField = new JTextField();
		nameTextField.setEditable(false);
		nameTextField.setBounds(162, 74, 105, 20);
		generalLayeredPane.add(nameTextField);
		nameTextField.setColumns(10);
		
		locationTextField = new JTextField();
		locationTextField.setEditable(false);
		locationTextField.setBounds(162, 99, 105, 20);
		generalLayeredPane.add(locationTextField);
		locationTextField.setColumns(10);
		
		contactpersonTextField = new JTextField();
		contactpersonTextField.setEditable(false);
		contactpersonTextField.setBounds(162, 126, 147, 20);
		generalLayeredPane.add(contactpersonTextField);
		contactpersonTextField.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("Type");
		lblNewLabel_5.setBounds(53, 157, 46, 14);
		generalLayeredPane.add(lblNewLabel_5);
		
		textField_4 = new JTextField();
		textField_4.setEditable(false);
		textField_4.setBounds(162, 154, 105, 20);
		generalLayeredPane.add(textField_4);
		textField_4.setColumns(10);
		
		JLabel lblNewLabel_6 = new JLabel("MAC Address");
		lblNewLabel_6.setBounds(53, 185, 72, 14);
		generalLayeredPane.add(lblNewLabel_6);
		
		textField_5 = new JTextField();
		textField_5.setEditable(false);
		textField_5.setBounds(162, 182, 126, 20);
		generalLayeredPane.add(textField_5);
		textField_5.setColumns(10);
		
		JLabel lblNewLabel_7 = new JLabel("IP Address");
		lblNewLabel_7.setBounds(53, 210, 72, 14);
		generalLayeredPane.add(lblNewLabel_7);
		
		textField_6 = new JTextField();
		textField_6.setEditable(false);
		textField_6.setBounds(161, 207, 127, 20);
		generalLayeredPane.add(textField_6);
		textField_6.setColumns(10);
		
		JButton btnNewButton = new JButton("OK");
		btnNewButton.setBounds(53, 305, 55, 23);
		generalLayeredPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("Cancel");
		btnNewButton_1.setBounds(216, 305, 72, 23);
		generalLayeredPane.add(btnNewButton_1);
		
		JLayeredPane layeredPane_1 = new JLayeredPane();
		tabbedPane.addTab("Security", null, layeredPane_1, null);
		
		JLabel lblNewLabel_8 = new JLabel("Community Strings");
		lblNewLabel_8.setBounds(122, 27, 91, 25);
		layeredPane_1.add(lblNewLabel_8);
		
		JRadioButton rdbtnNewRadioButton = new JRadioButton("Defaults");
		rdbtnNewRadioButton.setBounds(49, 66, 109, 23);
		layeredPane_1.add(rdbtnNewRadioButton);
		
		JLabel lblNewLabel_9 = new JLabel("Network Monitoring System will use the factory \r\ndefault community strings or any additional \r\ncommunity strings specified when this devices\r\n subnet was last discovered.");
		lblNewLabel_9.setBounds(49, 96, 254, 31);
		layeredPane_1.add(lblNewLabel_9);
		
		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("Specify");
		rdbtnNewRadioButton_1.setBounds(49, 146, 109, 23);
		layeredPane_1.add(rdbtnNewRadioButton_1);
		
		JLabel lblNewLabel_10 = new JLabel("Read");
		lblNewLabel_10.setBounds(64, 192, 46, 14);
		layeredPane_1.add(lblNewLabel_10);
		
		JLabel lblNewLabel_11 = new JLabel("Write");
		lblNewLabel_11.setBounds(64, 217, 46, 14);
		layeredPane_1.add(lblNewLabel_11);
		
		textField_7 = new JTextField();
		textField_7.setEditable(false);
		textField_7.setBounds(127, 189, 148, 20);
		layeredPane_1.add(textField_7);
		textField_7.setColumns(10);
		
		textField_8 = new JTextField();
		textField_8.setEditable(false);
		textField_8.setBounds(127, 214, 148, 20);
		layeredPane_1.add(textField_8);
		textField_8.setColumns(10);
		
		JButton btnNewButton_3 = new JButton("OK");
		btnNewButton_3.setBounds(49, 293, 61, 23);
		layeredPane_1.add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("Cancel");
		btnNewButton_4.setBounds(124, 293, 89, 23);
		layeredPane_1.add(btnNewButton_4);
		
		JButton btnNewButton_5 = new JButton("Help");
		btnNewButton_5.setBounds(234, 293, 70, 23);
		layeredPane_1.add(btnNewButton_5);
		
		JLayeredPane layeredPane_2 = new JLayeredPane();
		tabbedPane.addTab("Unit Information", null, layeredPane_2, null);
		
		JLabel lblNewLabel_12 = new JLabel("Model");
		lblNewLabel_12.setBounds(41, 45, 35, 14);
		layeredPane_2.add(lblNewLabel_12);
		
		JLabel lblNewLabel_13 = new JLabel("Firmware");
		lblNewLabel_13.setBounds(41, 70, 46, 14);
		layeredPane_2.add(lblNewLabel_13);
		
		JLabel lblNewLabel_14 = new JLabel("Last Down Time");
		lblNewLabel_14.setBounds(41, 95, 86, 14);
		layeredPane_2.add(lblNewLabel_14);
		
		JLabel lblNewLabel_15 = new JLabel("Frequency of Down Time");
		lblNewLabel_15.setBounds(41, 120, 126, 14);
		layeredPane_2.add(lblNewLabel_15);
		
		textField_9 = new JTextField();
		textField_9.setEditable(false);
		textField_9.setBounds(163, 42, 135, 20);
		layeredPane_2.add(textField_9);
		textField_9.setColumns(10);
		
		textField_10 = new JTextField();
		textField_10.setEditable(false);
		textField_10.setBounds(163, 67, 135, 20);
		layeredPane_2.add(textField_10);
		textField_10.setColumns(10);
		
		textField_11 = new JTextField();
		textField_11.setEditable(false);
		textField_11.setBounds(163, 92, 136, 20);
		layeredPane_2.add(textField_11);
		textField_11.setColumns(10);
		
		textField_12 = new JTextField();
		textField_12.setEditable(false);
		textField_12.setBounds(163, 120, 135, 20);
		layeredPane_2.add(textField_12);
		textField_12.setColumns(10);
		
		JButton btnNewButton_6 = new JButton("OK");
		btnNewButton_6.setBounds(54, 319, 52, 23);
		layeredPane_2.add(btnNewButton_6);
		
		JButton btnNewButton_7 = new JButton("Cancel");
		btnNewButton_7.setBounds(228, 319, 70, 23);
		layeredPane_2.add(btnNewButton_7);
		
		JLabel lblNewLabel_16 = new JLabel("History of Item");
		lblNewLabel_16.setBounds(41, 160, 77, 14);
		layeredPane_2.add(lblNewLabel_16);
		
		textField_13 = new JTextField();
		textField_13.setEditable(false);
		textField_13.setBounds(41, 176, 257, 80);
		layeredPane_2.add(textField_13);
		textField_13.setColumns(10);
		
		JLayeredPane layeredPane_3 = new JLayeredPane();
		tabbedPane.addTab("Connected Devices", null, layeredPane_3, null);
		
		table = new JTable();
		table.setBounds(329, 294, -297, -269);
		layeredPane_3.add(table);
		
	}
}
